package com.cqc.crm.dao.impl;

import java.io.Serializable;
import java.util.List;

import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Projections;
import org.springframework.orm.hibernate5.support.HibernateDaoSupport;

import com.cqc.crm.dao.CustomerDao;
import com.cqc.crm.domain.Customer;
import com.cqc.crm.utils.PageBean;

public class CustomerDaoImpl extends BaseDaoImpl<Customer> implements CustomerDao {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3635798891795874167L;

	/*
	@Override
	public PageBean<Customer> findByPage(Integer pageCode, Integer pageSize, DetachedCriteria criteria) {
		PageBean<Customer> page = new PageBean<>();
		page.setPageCode(pageCode);
		page.setPageSize(pageSize);
		
		criteria.setProjection(Projections.rowCount());
		List<Number> customerList = (List<Number>) getHibernateTemplate().findByCriteria(criteria);
		if(customerList!=null && customerList.size()>0) {
			page.setTotalCount(customerList.get(0).intValue());
		}
		criteria.setProjection(null);
		
		List<Customer> list = (List<Customer>) getHibernateTemplate().findByCriteria(criteria, (pageCode-1)*pageSize, pageSize);
		page.setBeanList(list);
		return page;
	}

	@Override
	public void add(Customer customer) {
		Long serializable =  (Long) getHibernateTemplate().save(customer);
	}

	@Override
	public Customer findCustomerById(Long cust_id) {
		List<Customer> list = (List<Customer>) getHibernateTemplate().find("from Customer where cust_id=?", cust_id);
		if(list!=null &&list.size()>0) {
			return list.get(0);
		}
		return null;
	}

	@Override
	public void update(Customer customer) {
		getHibernateTemplate().update(customer);
	}
*/
}
